﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w2.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    <title>Google Maps API Example - Google North America Offices</title> 
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxQcTQoRJ_JVFHVwderj38GcfiXt6hQX5E6h3W3sV-l-QbtgIls1pN0iAw"
            type="text/javascript"></script> 
    <script src="google_northamerica_offices.js" type="text/javascript"></script> 
    <script src="../src/markermanager.js"></script> 
    <script type="text/javascript"> 
    //<![CDATA[ 
    var map; 
    var mgr; 
    var icons = {}; 
    var allmarkers = []; 
 
    function load() { 
      if (GBrowserIsCompatible()) { 
        map = new GMap2(document.getElementById("map")); 
        map.addControl(new GLargeMapControl()); 
        map.addControl(new GOverviewMapControl()); 
        map.setCenter(new GLatLng(50, -98), 3); 
        map.enableDoubleClickZoom(); 
        mgr = new MarkerManager(map, {trackMarkers:true}); 
        window.setTimeout(setupOfficeMarkers, 0); 
      } 
    } 
 
    function getIcon(images) { 
      var icon = null; 
      if (images) { 
        if (icons[images[0]]) { 
          icon = icons[images[0]]; 
        } else { 
          icon = new GIcon(); 
          icon.image = "images/" 
              + images[0] + ".png"; 
          var size = iconData[images[0]]; 
          icon.iconSize = new GSize(size.width, size.height); 
          icon.iconAnchor = new GPoint(size.width >> 1, size.height >> 1);
          icon.shadow = "images/" 
              + images[1] + ".png";
          size = iconData[images[1]];
          icon.shadowSize = new GSize(size.width, size.height);
          icons[images[0]] = icon;
        }
      }
      return icon;
    }
 
    function setupOfficeMarkers() {
      allmarkers.length = 0;
      for (var i in officeLayer) {
        var layer = officeLayer[i];
        var markers = [];
        for (var j in layer["places"]) {
          var place = layer["places"][j];
          var icon = getIcon(place["icon"]);
          var title = place["name"];
          var posn = new GLatLng(place["posn"][0], place["posn"][1]);
          var marker = createMarker(posn,title,icon); 
          markers.push(marker);
          allmarkers.push(marker);
        }
        mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]);
      }
      mgr.refresh();
    }
  
    function createMarker(posn, title, icon) {
      var marker = new GMarker(posn, {title: title, icon: icon, draggable:true });
      GEvent.addListener(marker, 'dblclick', function() { mgr.removeMarker(marker) } ); 
      return marker;
    }
 
    function deleteMarker() {
      var markerNum = parseInt(document.getElementById("markerNum").value);
      mgr.removeMarker(allmarkers[markerNum]);
    }
   
    function clearMarkers() {
      mgr.clearMarkers();
    }
   
    function reloadMarkers() {
      setupOfficeMarkers();
    }
    //]]>
    </script> 
 
  </head> 
  <body onload="load()" onunload="GUnload()"> 
    <input type="button" onclick="deleteMarker()" value="delete marker #:" /> 
    &nbsp;
    <input type="text" id="markerNum" value="0" size="3"/> 
    |
    <input type="button" onclick="clearMarkers()" value="clear all markers" /> 
    |
    <input type="button" onclick="reloadMarkers()" value="reload all markers" /> 
 
    <br/> 
    <div id="map" style="width: 600px; height: 400px;"></div> 
  </body> 
</html> 
 <script>

/*






			
			
					
			if(vlat==0 && vlong==0){
				var geocoder = new GClientGeocoder();

				 var address=data.viewer.cl.l+", "+data.viewer.cl.r+" ,"+data.viewer.cl.c;
				  geocoder.getLatLng(address,
					function(point) {
					  if (!point) {
						vPopupHTML=vPopupHTML.replace(/Location:/"Location:<BR><font color='#993300'>[not detected]</font><BR>");
					  } else {
						map.setCenter(point, 1);
						var timegap=window.setTimeout(function(){ map.setZoom(8);} , 6000);
						//var marker = new GMarker(point);
						//map.addOverlay(marker);
						//marker.openInfoWindowHtml(address);
					  }
					  map.openInfoWindowHTML(map.getCenter(), vPopupHTML);
					}
				  );



			}else{	
				map.setCenter(new google.maps.LatLng(vlat, vlong), 1);
				map.openInfoWindowHTML(map.getCenter(), vPopupHTML);
				var timegap=window.setTimeout(function(){ map.setZoom(8);} , 6000);
			}



			
			if(data.owner.url!=data.viewer.url){
				if( olat==0 && olong==0){
				
				
				}else{
				map.openInfoWindowHTML(new google.maps.LatLng(olat, olong), oPopupHTML);
				}
			}












			//map.setCenter(new GLatLng(37.4419, -122.1419), 13);
			//map.openInfoWindow(map.getCenter(),  document.createTextNode("Hello, world"));

			// map.panTo(new GLatLng(37.4569, -122.1569));
			// map.setMapType(G_SATELLITE_MAP);//G_HYBRID_MAP//G_NORMAL_MAP


var bounds = map.getBounds();
  var southWest = bounds.getSouthWest();
  var northEast = bounds.getNorthEast();
  var lngSpan = northEast.lng() - southWest.lng();
  var latSpan = northEast.lat() - southWest.lat();
  for (var i = 0; i < 10; i++) {
    var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
        southWest.lng() + lngSpan * Math.random());
    map.addOverlay(new GMarker(point));
	
	
	
	---------------
	
	var geocoder = new GClientGeocoder();

function showAddress(address) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 13);
        var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(address);
      }
    }
  );
}




You can also modify the Maps API geocoder to prefer results within a given viewport (expressed as a bounding box of type GLatLngBounds) through the GClientGeocoder.setViewport() method. You can return results tailored to a particular domain (country) using the GClientGeocoder.setBaseCountryCode() method. Geocoding requests can be sent for every domain in which the main Google Maps application offers geocoding. For example, searches for "Toledo" will return different results within the domain of Spain (http://maps.google.es) specified by a country code of "es" than within the default domain within the United States (http://maps.google.com).





Extracting Structured Addresses
If you would like to access structured information about an address, GClientGeocoder also provides a getLocations() method that returns a JSON object consisting of the following information:
Status
request -- The request type. In this case, it is always geocode.
code -- A response code (similar to HTTP status codes) indicating whether the geocode request was successful or not. See the full list of status codes.
Placemark -- Multiple placemarks may be returned if the geocoder finds multiple matches.
address -- A nicely formatted and properly capitalized version of the address.
AddressDetails -- The address formatted as xAL, or eXtensible Address Language, an international standard for address formatting.
Accuracy -- An attribute indicating how accurately we were able to geocode the given address. See a list of possible values.
Point -- A point in 3D space.
coordinates -- The longitude, latitude, and altitude of the address. In this case, the altitude is always set to 0.
Here we show the JSON object returned by the geocoder for the address of Google's headquarters:
{
  "name": "1600 Amphitheatre Parkway, Mountain View, CA, USA",
  "Status": {
    "code": 200,
    "request": "geocode"
  },
  "Placemark": [
    {
      "address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
      "AddressDetails": {
        "Country": {
          "CountryNameCode": "US",
          "AdministrativeArea": {
            "AdministrativeAreaName": "CA",
            "SubAdministrativeArea": {
              "SubAdministrativeAreaName": "Santa Clara",
              "Locality": {
                "LocalityName": "Mountain View",
                "Thoroughfare": {
                  "ThoroughfareName": "1600 Amphitheatre Pkwy"
                },
                "PostalCode": {
                  "PostalCodeNumber": "94043"
                }
              }
            }
          }
        },
        "Accuracy": 8
      },
      "Point": {
        "coordinates": [-122.083739, 37.423021, 0]
      }
    }
  ]
}
In this example, we use the getLocations() method to geocode addresses, and extract the nicely formatted version of the address and the two-letter country from the JSON and display it in the info window.
var map;
var geocoder;

function addAddressToMap(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("\"" + address + "\" not found");
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],
                        place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml(place.address + '<br>' + 
      '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  }
}
View example (geocoding-extraction.html)
Geocoding Caches
GClientGeocoder is equipped with a client-side cache by default. The cache stores geocoder responses, enabling faster responses if addresses are re-geocoded. You can turn off caching by passing null to the setCache() method of the GClientGeocoder object. However, we recommend that you leave caching on as it improves performance. To change the cache being used by GClientGeocoder, call setCache() and pass in the new cache. To empty the contents of the current cache, call the reset() method on the geocoder or on the cache directly.
Developers are encouraged to build their own client-side caches. In this example, we construct a cache that contains pre-computed geocoder responses to six capital cities in countries covered by geocoding API. First, we build an array of geocode responses. Next, we create a custom cache that extends a standard GeocodeCache. Once the cache is defined, we call the setCache() method. There is no strict checking of objects stored in the cache, so you may store other information (such as population size) in the cache as well.

// Builds an array of geocode responses for the 6 capitals
var city = [
  {
    name: "Washington, DC",
    Status: {
      code: 200,
      request: "geocode"
    },
    Placemark: [
      {
        address: "Washington, DC, USA",
        population: "0.563M",
        AddressDetails: {
          Country: {
            CountryNameCode: "US",
            AdministrativeArea: {
              AdministrativeAreaName: "DC",
              Locality: {
                LocalityName: "Washington"
              }
            }
          },
          Accuracy: 4          
        },
        Point: {
          coordinates: [-77.036667, 38.895000, 0]
        }
      }
    ]
  },
  ... // etc., and so on for other cities
];

  var map;
  var geocoder;

  // CapitalCitiesCache is a custom cache that extends the standard GeocodeCache.
  // We call apply(this) to invoke the parent's class constructor.
  function CapitalCitiesCache() {
    GGeocodeCache.apply(this);
  }

  // Assigns an instance of the parent class as a prototype of the
  // child class, to make sure that all methods defined on the parent
  // class can be directly invoked on the child class.
  CapitalCitiesCache.prototype = new GGeocodeCache();

  // Override the reset method to populate the empty cache with
  // information from our array of geocode responses for capitals.
  CapitalCitiesCache.prototype.reset = function() {
    GGeocodeCache.prototype.reset.call(this);
    for (var i in city) {
      this.put(city[i].name, city[i]);
    }
  }

  map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(new GLatLng(37.441944, -122.141944), 6);

  // Here we set the cache to use the UsCitiesCache custom cache.
  geocoder = new GClientGeocoder();
  geocoder.setCache(new CapitalCitiesCache());
	



*/
</script>